//
//  YGFoodDetailHeadCell.m
//  yuanshangyiliao
//
//  Created by admin on 2021/4/30.
//

#import "YGFoodDetailHeadCell.h"

@interface YGFoodDetailHeadCell ()
@property (nonatomic, strong) UIImageView *imgView;
@property (nonatomic, strong) UILabel *nameLabel;
@property (nonatomic, strong) UILabel *contentLabel;
@property (nonatomic, strong) UIView *containView;
@end

@implementation YGFoodDetailHeadCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self.contentView addSubview:self.containView];
        [self.containView addSubview:self.imgView];
        
        [self.containView addSubview:self.nameLabel];
        [self.containView addSubview:self.contentLabel];
        
        [self.containView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.left.offset(10);
            make.bottom.right.offset(-10);
//            make.height.greaterThanOrEqualTo(@(120)).priorityLow();
        }];
        
        [self.imgView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.height.offset(100);
            make.left.offset(10);
            make.centerY.offset(0);
        }];
        
        [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.offset(0);
            make.left.equalTo(self.imgView.mas_right).offset(10);

        }];
        
        [self.contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.nameLabel.mas_right).offset(10);
            make.top.offset(10);
            make.bottom.offset(-10);
            make.right.offset(-10);
            make.height.greaterThanOrEqualTo(@(120));
        }];
    }
    return self;
}


- (void)setModel:(YGFoodDetailModel *)model {
    _model = model;
    [self.imgView sd_setImageWithURL:[NSURL URLWithString:model.thumbnail] placeholderImage:nil];
    self.contentLabel.text = model.content;
    self.nameLabel.text = model.name;
}


#pragma mark - Getter

- (UIImageView *)imgView
{
    if(!_imgView){
        _imgView = [[UIImageView alloc] init];
    }
    return _imgView;
}

- (UILabel *)nameLabel
{
    if(!_nameLabel){
        _nameLabel = [[UILabel alloc] init];
    }
    return _nameLabel;
}

- (UILabel *)contentLabel
{
    if(!_contentLabel){
        _contentLabel = [[UILabel alloc] init];
        _contentLabel.numberOfLines = 0;
    }
    return _contentLabel;
}


- (UIView *)containView
{
    if(!_containView){
        _containView = [[UIView alloc] init];
    }
    return _containView;
}

@end
